<template>
  <div class="container">
    <!-- 内容展示区 -->
    <div ref="screen" class="screen">
      <div class="top">
        <Top />
      </div>
      <div class="bottom">
        <div class="left">
          <Tourist class="tourist" />
          <Sex class="sex" />
          <Age class="age" />
        </div>
        <div class="center">
          <Map class="map" />
          <Line class="line" />
        </div>
        <div class="right">
          <Rank class="rank" />
          <Year class="year" />
          <Couter class="couter" />
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import Top from './components/Top/index.vue'
import Tourist from './components/tourist/index.vue'
import Sex from './components/sex/index.vue'
import Age from './components/age/index.vue'
import Map from './components/map/index.vue'
import Line from './components/line/index.vue'
import Rank from './components/rank/index.vue'
import Year from './components/year/index.vue'
import Couter from './components/couter/index.vue'
//获取DOM元素
let screen = ref()
//组件挂载后将元素初步缩放
onMounted(() => {
  screen.value.style.transform = `scale(${getScale()}) translate(-50%,-50%)`
})
//定义一个方法计算scale缩放的值
function getScale(w = 1920, h = 1080) {
  let ww = window.innerWidth / w
  let hh = window.innerHeight / h
  return ww < hh ? ww : hh
}
//监听视口变化
window.onresize = function () {
  screen.value.style.transform = `scale(${getScale()}) translate(-50%,-50%)`
}
</script>

<style scoped lang="scss">
.container {
  width: 100vw;
  height: 100vh;
  background: url('./images/bg.png') no-repeat;
  background-size: cover;
  .screen {
    position: fixed;
    width: 1920px;
    height: 1080px;
    left: 50%;
    top: 50%;
    // 缩放奇点，使得缩放奇点处于屏幕正中央
    transform-origin: left top;
  }
  .top {
    width: 100%;
    height: 40px;
  }
  .bottom {
    display: flex;
    .left {
      flex: 1;
      height: 1040px;
      display: flex;
      flex-direction: column;
      .tourist {
        flex: 1;
      }
      .sex {
        flex: 1;
      }
      .age {
        flex: 1;
      }
    }
    .center {
      flex: 2;
      display: flex;
      flex-direction: column;
      .map {
        flex: 4;
      }
      .line {
        flex: 1;
      }
    }
    .right {
      flex: 1;
      display: flex;
      flex-direction: column;
      .rank {
        flex: 1;
      }
      .year {
        flex: 1;
      }
      .couter {
        flex: 1;
      }
    }
  }
}
</style>
